//
//  QcDoctorApplyController.m
//  QcMedical1
//
//  Created by jiawen Du on 2016/12/21.
//  Copyright © 2016年 jiawen Du. All rights reserved.
//

#import "QcDoctorApplyController.h"
#import "NetWorkTool.h"
#import "QcDoctorsIfonModel.h"


@interface QcDoctorApplyController ()



@end

@implementation QcDoctorApplyController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}



- (void)setupUI {
    
    self.navigationItem.title = @"医生详情";
    
    [self.DoctorPicture sd_setImageWithURL:[NSURL URLWithString:_model.doctor_portrait]placeholderImage:[UIImage imageNamed:@"aa"]];
    
    self.bannerNumber.text = [@"获得锦旗数:" stringByAppendingString:self.model.banner.description];
    self.treatNumber.text = [@"当前预约数量:" stringByAppendingString:self.model.operation_count.description];
    self.Qchospital.text = self.model.doctor_hospital_name;
    self.DoctorName.text = self.model.doctor_name;
    self.DoctorSex.text = self.model.doctor_gender.intValue ? @"性别:男":@"性别:女";
    self.cureRate.text = [NSString stringWithFormat:@"治愈率:%@",self.model.accuracy];
    
    [self.label_stats setTextColor:[UIColor redColor]];
    
    if (self.ifmodel.applyState.intValue == 1) {
        self.label_stats.text = @"已申请";
        self.imageView_blue.backgroundColor = [UIColor colorWithRed:69/255.0 green:178/255.0 blue:175/255.0 alpha:1];
        
        [self.label_stats setTextColor:[UIColor whiteColor]];
        
    }
    
    if (self.ifmodel.applyState.intValue == 0) {
        self.label_stats.text = @"未申请";
        self.imageView_blue.backgroundColor =[UIColor lightGrayColor];
        
        [self.label_stats setTextColor:[UIColor redColor]];
    }
    
}

#pragma mark
#pragma mark - 取消申请
- (IBAction)cancel:(id)sender {
    
    
    UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"取消预约？" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"我再想想" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        //取消预约
        [self chooseCancal];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:deleteAction];
    

    
    [self presentViewController:alertController animated:YES completion:nil];
    


}

- (void)chooseCancal{
    
  
    
    NSNumber *state = @(0);
    
    self.ifmodel.applyState = state;
    
    if (_stateBlock) {
        _stateBlock(self.ifmodel);
    }
    
    [self.navigationController popViewControllerAnimated:YES];

}


#pragma mark
#pragma mark - 我要申请
- (IBAction)add:(id)sender {
    

    NSNumber* state = @(1);
    
    self.ifmodel.applyState =state;
    
    if(_stateBlock){
        
        _stateBlock(self.ifmodel);
     //   NSLog(@"回传的model%p",self.ifmodel);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
    
}

@end
